package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.pojo.Feedback;
import com.itheima.entity.Result;
import com.itheima.service.FeedBackService;
import com.itheima.vo.FeedbackVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户反馈接口
 */
@Controller
@RequestMapping("/feedback")
public class FeedBackController {
    @Autowired
    private FeedBackService feedBackService;

    /**
     * 批量删除反馈
     *
     * @param feedbackVOList 反馈集合
     * @param model
     * @return
     */
    @PostMapping("/deleteBatch")
    @ResponseBody
    public Result deleteMany(@RequestBody List<FeedbackVo> feedbackVOList, Model model) {

        try {
            feedBackService.deleteBatch(feedbackVOList);
            return new Result();
        } catch (Exception e) {
            return new Result("操作失败");
        }

    }

    /**
     * 反馈列表
     *
     * @param feedbackVO 前端传递的实体类
     * @param model
     * @return
     */
    @PostMapping("/getList")
    @ResponseBody
    public Result list(@RequestBody(required = false) FeedbackVo feedbackVO, Model model) {
        System.out.println("111");
        PageInfo<Feedback> pageInfo = feedBackService.list(feedbackVO);
        Result result = new Result("success", pageInfo);
        model.addAttribute("result", result);
        return result;
    }

    /**
     * 编辑反馈
     *
     * @param feedbackVO 前端传递的实体类
     * @param model
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Result edit(@RequestBody FeedbackVo feedbackVO, Model model) {
        feedBackService.edit(feedbackVO);
        model.addAttribute("result", new Result<>());
        return new Result();
    }
}
